<template>
	<view class="bg">
		<u-modal v-model="show" :content="content" :show-cancel-button='true' @confirm="confirm"></u-modal>
		<u-toast ref="uToast" />
		<view class="bg_bottom">
			<u-form :model="xmjzFrom" ref="uForm" :rules="rules" label-width="160" :label-style="{
			  fontSize: '24rpx',
			  fontFamily: 'PingFang SC',
			  fontWeight: '400',
			  color: '#272B32',
			}">
				<view class="item">
					<u-form-item label-width="200" label="项目名称">
						{{xmjzFrom.itemCode_dictText}}
					</u-form-item>
					<u-form-item label-width="200" label="数据时间">
						{{xmjzFrom.dataTime}}
					</u-form-item>
					<u-form-item label-width="200" label="报送周期">
						{{xmjzFrom.fillCycle_dictText}}
					</u-form-item>
					<u-form-item label-width="200" label="本年度计划投资">
						{{dataObj.yearPlanInv}}(万元)
					</u-form-item>
					<u-form-item label-width="200" label="计划投资">
						{{dataObj.planInvTotal}}(万元)
					</u-form-item>
				</view>
				<view class="item">
					<u-form-item label-width="350" label="本年累计投资额(万元)" :required="true" prop="yearInvTotal">
						<u-input v-model="xmjzFrom.yearInvTotal" placeholder="请输入投资额" :clearable='false' />
					</u-form-item>
					<u-form-item label-width="350" label="累计投资额(万元)" :required="true" prop="invTotal">
						<u-input v-model="xmjzFrom.invTotal" placeholder="请输入投资额" :clearable='false' />
					</u-form-item>
				</view>
				<view class="sub_title">进展填报</view>
				<view class="item">
					<u-form-item label="形象进度" label-position="top" :required="true" prop="imageProgress">
						<u-input v-model="xmjzFrom.imageProgress" type="textarea" placeholder="请输入形象进度" />
					</u-form-item>
				</view>
				<view class="item">
					<u-form-item label="下一步计划" label-position="top" :required="true" prop="nextPlan">
						<u-input v-model="xmjzFrom.nextPlan" type="textarea" placeholder="请输入下一步计划" />
					</u-form-item>
				</view>
				<view class="item">
					<u-form-item label="存在问题" label-position="top" :required="true" prop="problems">
						<u-input v-model="xmjzFrom.problems" type="textarea" placeholder="请输入存在的问题" />
					</u-form-item>
				</view>
			</u-form>
		</view>

		<view class="tqxt_buttons">
			<view @click="jump">查看历史</view>
			<view @click="Submit">提交</view>
			<view @click="tips">建设已完成</view>
		</view>
	</view>
</template>

<script>
	import {
		xmjzJztbDetail,
		xmjzJztbSubmit,
		xmjzJztbComplete
	} from "@/request/zdxm.js"
	export default {
		data() {
			return {
				btnType: null,
				content: '',
				show: false,
				dataObj: {},
				xmjzFrom: {
					invTotal: 0,
					yearInvTotal: 0,
					bzqwctz: "",
					jdqk: "",
					xbjh: "",
					czwt: ""
				},
				rules: {
					yearInvTotal: [{
						required: true,
						message: '请输入本年累计投资额',
					}],
					invTotal: [{
						required: true,
						message: '请输入累计投资额',
					}],
					imageProgress: [{
						required: true,
						message: '请输入形象进度',
						trigger: ['change', "blur"],
					}],
					nextPlan: [{
						required: true,
						message: '请输入下一步计划',
						trigger: ['change', "blur"],
					}],
					problems: [{
						required: true,
						message: '请输入存在的问题',
						trigger: ['change', "blur"],
					}]
				},
			};
		},
		onLoad(option) {
			console.log(JSON.parse(option.item))
			this.xmjzFrom = JSON.parse(option.item)
			this.xmjzJztbDetail()
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			jump(){
				uni.navigateTo({
				    url: '../../xmgl/xq/tbjzlsjl?id='+this.xmjzFrom.subProcessCode
				});
			},
			xmjzJztbDetail() {
				xmjzJztbDetail({
						itemCode: this.xmjzFrom.id
					})
					.then((res) => {
						this.dataObj = res.data.result
						this.xmjzFrom.invTotal = res.data.result.invTotal
						this.xmjzFrom.yearInvTotal = res.data.result.yearInvTotal
					})
			},
			Submit() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
						// 提交确认
						this.btnType = 1
						this.show = true;
						this.content = '是否提交该项目进展进展填报'
					} else {
						console.log('验证失败');
					}
				});
			},
			tips() {
				// 完成以建设确认
				this.btnType = 2
				this.show = true;
				this.content = '项目已建设完成，确定提交审核?'
			},
			confirm() {
				if (this.btnType === 1) {
					xmjzJztbSubmit({
						cycleInv: this.dataObj.cycleInv,
						yearPlanInv: this.dataObj.yearPlanInv,
						dataTime: this.xmjzFrom.dataTime,
						fillCycle: this.xmjzFrom.fillCycle,
						imageProgress: this.xmjzFrom.imageProgress,
						invTotal: this.xmjzFrom.invTotal,
						nextPlan: this.xmjzFrom.nextPlan,
						problems: this.xmjzFrom.problems,
						subProcessCode: this.xmjzFrom.subProcessCode,
						yearInvTotal: this.xmjzFrom.yearInvTotal,
						mainProcessCode: this.xmjzFrom.mainProcessCode,
						itemPlanInv: this.xmjzFrom.invTotal,
						itemCode: this.xmjzFrom.itemCode,
						processType: '2'
					}).then((res) => {
						if (res.data.code === 200) {
							this.$refs.uToast.show({
								title: res.data.message,
								type: "success",
								duration: 2000,
								callback() {
									uni.navigateBack({
										delta: 1
									});
								}
							});
						}
					})
				} else if (this.btnType === 2) {
					xmjzJztbComplete({
							subProcessCode: this.xmjzFrom.subProcessCode
						})
						.then((res) => {
							if (res.data.code === 200) {
								this.$refs.uToast.show({
									title: res.data.message,
									type: "success",
									duration: 2000,
									callback() {
										uni.redirectTo({
											url: '../../todo/index'
										});
									}
								});
							}
						})
				}
			}
		},
	};
</script>

<style lang="scss" scoped>
	.bg_bottom {
		padding-bottom: 98rpx;
	}

	.tqxt_buttons {
		width: 100%;
		height: 98rpx;
		line-height: 98rpx;
		text-align: center;
		display: flex;
		flex-flow: row nowrap;
		justify-content: flex-start;
		align-content: center;
		position: fixed;
		bottom: 0;
		left: 0;

		view:nth-child(1) {
			flex: 1;
			background: #ffffff;
			border: 1rpx solid #e7e9f0;
			font-size: 36rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #8e9cb3;
		}

		view:nth-child(2) {
			flex: 1;
			background: #3074ff;
			font-size: 36rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #fefefe;
		}

		view:nth-child(3) {
			flex: 1;
			background: #ff9900;
			font-size: 36rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #fefefe;
		}
	}

	.item {
		width: 100%;
		margin: 0 auto;
		margin-bottom: 30rpx;
		background: #ffffff;
		box-shadow: 0rpx 0rpx 24rpx 0rpx rgba(48, 116, 255, 0.1);
		border-radius: 8rpx;
		padding: 0 30rpx;

		// display: flex;
		// align-items: flex-start;
		.itemOne {
			display: flex;
			align-items: flex-start;
		}
	}

	.sub_title {
		padding-left: 20rpx;
		height: 30rpx;
		line-height: 30rpx;
		text-align: left;
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #3074ff;
	}

	.button {
		width: 100%;
		height: 98rpx;
		line-height: 98rpx;
		background: #3074ff;
		font-size: 36rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #ffffff;
		text-align: center;
	}
</style>
